﻿using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

namespace Sgr.OmniMetrics.Services
{
    /// <summary>
    /// OmniMetric 数据服务接口
    /// </summary>
    public interface IOmniMetricService
    {
        /// <summary>
        /// 保存或更新指标数据
        /// </summary>
        /// <typeparam name="T">扩展数据类型</typeparam>
        /// <param name="metric">指标数据</param>
        /// <param name="cancellationToken">取消令牌</param>
        /// <returns>保存后的指标数据</returns>
        Task<OmniMetric<T>> SaveMetricAsync<T>(OmniMetric<T> metric, CancellationToken cancellationToken = default) where T : class;

        /// <summary>
        /// 批量保存或更新指标数据
        /// </summary>
        /// <typeparam name="T">扩展数据类型</typeparam>
        /// <param name="metrics">指标数据集合</param>
        /// <param name="cancellationToken">取消令牌</param>
        Task SaveMetricsAsync<T>(IEnumerable<OmniMetric<T>> metrics, CancellationToken cancellationToken = default) where T : class;

        /// <summary>
        /// 获取最新的指标数据
        /// </summary>
        /// <typeparam name="T">扩展数据类型</typeparam>
        /// <param name="metricKey">指标标识</param>
        /// <param name="granularity">统计粒度</param>
        /// <param name="cancellationToken">取消令牌</param>
        /// <returns>最新的指标数据</returns>
        Task<OmniMetric<T>?> GetLatestMetricAsync<T>(
            string metricKey,
            Granularity granularity,
            CancellationToken cancellationToken = default) where T : class;

        /// <summary>
        /// 获取指定时间范围内的指标数据
        /// </summary>
        /// <typeparam name="T">扩展数据类型</typeparam>
        /// <param name="metricKey">指标标识</param>
        /// <param name="granularity">统计粒度</param>
        /// <param name="startTime">起始时间</param>
        /// <param name="endTime">结束时间</param>
        /// <param name="cancellationToken">取消令牌</param>
        /// <returns>指标数据列表</returns>
        Task<IReadOnlyList<OmniMetric<T>>> GetMetricsAsync<T>(
            string metricKey,
            Granularity granularity,
            DateTime startTime,
            DateTime endTime,
            CancellationToken cancellationToken = default) where T : class;

        /// <summary>
        /// 删除指定时间范围内的指标数据
        /// </summary>
        /// <param name="metricKey">指标标识</param>
        /// <param name="granularity">统计粒度</param>
        /// <param name="startTime">起始时间</param>
        /// <param name="endTime">结束时间</param>
        /// <param name="cancellationToken">取消令牌</param>
        Task DeleteMetricsAsync(
            string metricKey,
            Granularity granularity,
            DateTime startTime,
            DateTime endTime,
            CancellationToken cancellationToken = default);
    }
}